package com.wisecoach.gatewayplus.utils;

import org.hyperledger.fabric.client.identity.Identities;
import org.hyperledger.fabric.client.identity.Signer;
import org.hyperledger.fabric.client.identity.Signers;

import java.io.FileReader;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;

/**
 * {@code @author:} wisecoach
 * {@code @date:} 2023/6/15 上午3:08
 * {@code @version:} 1.0.0
 */


public class GatewayUtils {

    public static Signer getSignerByFile(String filePath) {
        try {
            FileReader reader = new FileReader(filePath);
            PrivateKey privateKey = Identities.readPrivateKey(reader);
            return Signers.newPrivateKeySigner(privateKey);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static X509Certificate getCertByFile(String filePath) {
        try {
            FileReader reader = new FileReader(filePath);
            return Identities.readX509Certificate(reader);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
